package com.learn.spring;

import com.learn.spring.entity.FluxUser;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

public class WebfluxClient {

    public static void main(String[] args) {
        WebClient webClient = WebClient.create("http://127.0.0.1:8088");

        // 根据ID查询
        String id = "1";
        FluxUser user = webClient.get().uri("/user/{id}", id).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono(FluxUser.class).block();
        System.out.println(user);

        // 查询所有
        Flux<FluxUser> users = webClient.get().uri("/user").accept(MediaType.APPLICATION_JSON).retrieve().bodyToFlux(FluxUser.class);
        users.map(user1 -> user1.getName()).buffer().doOnNext(System.out::println).blockFirst();

//        webClient.post().uri("/user", new FluxUser("ceshi1","nan",22)).accept(MediaType.APPLICATION_JSON).retrieve().bodyToMono().block();

    }
}
